<template>
    <div class="contioner">
        <div class="search-form divClass" v-show="headerShow" style="padding-top: 15px">
            <a-form size="small" :model="query" layout="inline">
                <a-form-item label="日期" prop="beginDate">
                    <a-year-picker v-model="query.beginDate" :style="{ width: '180px' }" placeholder="选择开始日期"
                        class="bacClass" />
                </a-form-item>
                <CorporateSectorCascader :configCascader="configCascader" @changeCascader="changeCascader" />
            </a-form>
            <div class="my-tool-bar" style="margin-bottom: 5px">
                <a-space>
                    <el-button type="primary" :icon="Search" @click="getList">查询</el-button>
                    <el-button pain @click="emit('takebiaoji', 0)" plain>返回主页</el-button>
                </a-space>
            </div>
        </div>
        <div class="my-divisders">
            <a-divider orientation="center">
                <icon-double-up v-if="headerShow" @click="headerShow = false" :strokeWidth="2" :size="18" />
                <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18" />
            </a-divider>
        </div>

        <div style="background-color: #f0f2f5; height: 10px"></div>
        <div :style="{ height: '89%', width: '100%', padding: '10px', display: 'flex', justifyContent: 'space-between', }">
            <div :style="{ height: '100%', width: '65%' }">
                <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" rowSelection="multiple" @grid-ready="gridReady"
                    @click="gridClicks" style="height:100%" :defaultColDef="defaultColDef" class='ag-theme-alpine'
                    :rowData="tableDataList" :columnDefs="tc">
                </AgGridVuesCopys>
            </div>
            <div :style="{ height: '100%', width: '33%' }">
                <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" rowSelection="multiple" style="height:100%"
                    :defaultColDef="defaultColDef" class='ag-theme-alpine' :rowData="tableDataList2" :columnDefs="tc2">
                </AgGridVuesCopys>
            </div>
        </div>
    </div>
</template>
    
<script lang="ts" setup>


import { Message } from '@arco-design/web-vue'
import { ref, reactive, onMounted, watch } from 'vue'
import CorporateSectorCascader from '@/components/corporateSectorCascader/inde.vue'
// 引入element提示
//引入封装post
import { post } from '@/api/http'
import { Search, EditPen } from '@element-plus/icons-vue'
import dayjs from 'dayjs'
const emit = defineEmits(['takebiaoji'])
const headerShow = ref<boolean>(true)


const configCascader = ref<{}>({
    corporateWidth: '200px', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: false, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '厂区', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
})
const changeCascader = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    query.planOrderCode = corporateId
}

interface Querin {
    beginDate: any
    planOrderCode: any
}
//getlist初始化接口参数
let query = reactive<Querin>({
    beginDate: dayjs().format('YYYY'), //当天日期
    planOrderCode: '',
})

const tableDataList: any = ref([])
const tableDataList2: any = ref([])
const gridOption = ref()
const gridReady = (params: any) => {
    gridOption.value = params.api
}
const defaultColDef = {
    sortable: true,
    resizable: true,
    filter: true,
    flex: 1
}

const tc = [
    {
        headerName: '日期',
        field: 'dateByMonth',
        width: 120
    },
    {
        headerName: '日产目标值（吨/天）',
        field: 'goalByDay',
        width: 150
    },
    {
        headerName: '日均产量（吨/天）',
        field: 'outputByDay',
        width: 150
    },
    {
        headerName: '月目标',
        field: 'goalByMonth',
        width: 150
    },
    {
        headerName: '累计总产量（吨）',
        field: 'outputByTotal',
        width: 150
    },
]

const tc2 = [
    {
        headerName: '日期',
        field: 'dateByDay',
        width: 110
    },
    {
        headerName: '日产目标值（吨/天）',
        field: 'goalByDay',
        width: 160
    },
    {
        headerName: '日产量（吨/天）',
        field: 'outputByDay',
        width: 150
    },
]


function selectJt() {
    if(!query.planOrderCode){Message.warning('公司必填'); return false;}
    post({
        url: 'qms/report/companyOutputReport',
        data: {
            "firmId": query.planOrderCode,
            "year": Number(query.beginDate),
        }
    }).then((res: any) => {
        if (res.code == 200) {
            tableDataList.value = res.data
        } else {
            Message.error(res.message)
        }
    })
}


const getList = () => {
    selectJt()
}

const gridClicks = () => {
    post({
        url: 'qms/report/companyOutputReportByDay',
        data: {
            firmId:query.planOrderCode,
            date:gridOption.value.getSelectedRows()[0].dateByMonthPattern
        }
    }).then((res:any)=>{
        if(res.code == 200){
            tableDataList2.value =  res.data
        }else{
            Message.warning(res.message)
        }
    })
}
</script>
<style scoped lang="less">
.contioner {
    height: 100%;
    background: #fff;
}

:deep(.ag-cell) {
    border-right: 1px solid #dde2eb;
}

:deep(.ag-header-cell) {
    border-right: 1px solid #dde2eb;
}

:deep(.ag-cell-value) {
    user-select: initial;
    -moz-user-select: text;
    -ms-user-select: text;
    -webkit-user-select: text;
}
</style>
      